<?php

/**
 * This is the model class for table "{{pais}}".
 *
 * The followings are the available columns in table '{{pais}}':
 * @property integer $pais_id
 * @property integer $pais_isonum
 * @property string $pais_iso2
 * @property string $pais_iso3
 * @property string $pais_nombre
 * @property string $pais_nacionalidad
 *
 * The followings are the available model relations:
 * @property Persona[] $personas
 * @property Persona[] $personas1
 */
class Pais extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Pais the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{pais}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('pais_isonum', 'numerical', 'integerOnly'=>true),
			array('pais_iso2', 'length', 'max'=>2),
			array('pais_iso3', 'length', 'max'=>3),
			array('pais_nombre', 'length', 'max'=>80),
			array('pais_nacionalidad', 'length', 'max'=>200),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('pais_id, pais_isonum, pais_iso2, pais_iso3, pais_nombre, pais_nacionalidad', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'personas' => array(self::HAS_MANY, 'Persona', 'persona_pais'),
			'personas1' => array(self::HAS_MANY, 'Persona', 'persona_nacionalidad'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'pais_id' => 'Pais',
			'pais_isonum' => 'Pais Isonum',
			'pais_iso2' => 'Pais Iso2',
			'pais_iso3' => 'Pais Iso3',
			'pais_nombre' => 'Pais Nombre',
			'pais_nacionalidad' => 'Pais Nacionalidad',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('pais_id',$this->pais_id);
		$criteria->compare('pais_isonum',$this->pais_isonum);
		$criteria->compare('pais_iso2',$this->pais_iso2,true);
		$criteria->compare('pais_iso3',$this->pais_iso3,true);
		$criteria->compare('pais_nombre',$this->pais_nombre,true);
		$criteria->compare('pais_nacionalidad',$this->pais_nacionalidad,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}